package com.ruoyi.business.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.ruoyi.business.domain.bo.FileExportTypeBo;
import com.ruoyi.business.domain.vo.FileExportTypeVo;
import com.ruoyi.business.service.IFileExportTypeService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * ExportType
 *
 * @author ruoyi
 * @date 2025-01-15
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/business/exportType")
public class FileExportTypeController extends BaseController {

    private final IFileExportTypeService iFileExportTypeService;

    /**
     * 查询ExportType列表
     */
    @SaCheckPermission("business:exportType:list")
    @GetMapping("/list")
    public TableDataInfo<FileExportTypeVo> list(FileExportTypeBo bo, PageQuery pageQuery) {
        return iFileExportTypeService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出ExportType列表
     */
    @SaCheckPermission("business:exportType:export")
    @Log(title = "ExportType", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(FileExportTypeBo bo, HttpServletResponse response) {
        List<FileExportTypeVo> list = iFileExportTypeService.queryList(bo);
        ExcelUtil.exportExcel(list, "ExportType", FileExportTypeVo.class, response);
    }

    /**
     * 获取ExportType详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("business:exportType:query")
    @GetMapping("/{id}")
    public R<FileExportTypeVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(iFileExportTypeService.queryById(id));
    }

    /**
     * 新增ExportType
     */
    @SaCheckPermission("business:exportType:add")
    @Log(title = "ExportType", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody FileExportTypeBo bo) {
        return toAjax(iFileExportTypeService.insertByBo(bo));
    }

    /**
     * 修改ExportType
     */
    @SaCheckPermission("business:exportType:edit")
    @Log(title = "ExportType", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody FileExportTypeBo bo) {
        return toAjax(iFileExportTypeService.updateByBo(bo));
    }

    /**
     * 删除ExportType
     *
     * @param ids 主键串
     */
    @SaCheckPermission("business:exportType:remove")
    @Log(title = "ExportType", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(iFileExportTypeService.deleteWithValidByIds(Arrays.asList(ids), true));
    }
}
